package com.example.design.bridge.abst;

import com.example.design.bridge.function.RegisterLoginFuncInterface;
import com.example.design.pojo.UserInfo;

import javax.servlet.http.HttpServletRequest;
//桥接模式抽象类
public abstract class AbstractRegisterLoginComponent {

    //面向接口编程，引入 RegisterLoginFuncInterface。此处为“桥”之所在。
    protected RegisterLoginFuncInterface registerLoginFuncInterface;

    //通过构造参数，初始化RegisterLoginFuncInterface
    public AbstractRegisterLoginComponent(RegisterLoginFuncInterface registerLoginFuncInterface) {
        //检验构造参数是否为RegisterLoginFuncInterface且不能为空
        validate(registerLoginFuncInterface);
        this.registerLoginFuncInterface = registerLoginFuncInterface;

    }

    //final方法，不允许子类修改。
    protected final void validate(RegisterLoginFuncInterface funcInterface){
        if (funcInterface == null){
            throw new UnsupportedOperationException("不支持该功能");
        }
    }


    public abstract String login(String account, String password);

    public abstract String register(UserInfo userInfo);

    public abstract boolean checkUserExists(String userName);


    public abstract String login3rd(HttpServletRequest request);
}
